package cn.wolfcode.car.business.web.controller;


import cn.wolfcode.car.business.domain.Customer;
import cn.wolfcode.car.business.domain.CustomerLinkMane;
import cn.wolfcode.car.business.query.CustomerLinkManeQuery;
import cn.wolfcode.car.business.service.ICustomerLinkManeService;
import cn.wolfcode.car.business.service.ICustomerService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/customerLinkMane")
public class CustomerLinkManeController {
    //模板前缀
    private static final String prefix = "business/customerLinkMane/";

    @Autowired
    private ICustomerLinkManeService customerLinkManeService;

    @Autowired
    private ICustomerService iCustomerService;
    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:customerLinkMane:view")
    @RequestMapping("/listPage")
    public String listPage(Model model) {
        List<Customer> customers = iCustomerService.selectAll();
        model.addAttribute("customers",customers);
        return prefix + "list";

    }

    @RequiresPermissions("business:customerLinkMane:add")
    @RequestMapping("/addPage")
    public String addPage(Model model) {
        List<Customer> customerList = iCustomerService.selectAll();
        model.addAttribute("customerList",customerList);
        return prefix + "add";
    }


    @RequiresPermissions("business:customerLinkMane:edit")
    @RequestMapping("/editPage")
    public String editPage(Long id, Model model) {
        List<Customer> customerList = iCustomerService.selectAll();
        model.addAttribute("customerList",customerList);
        model.addAttribute("customerLinkMane", customerLinkManeService.get(id));
        return prefix + "edit";
    }

    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:customerLinkMane:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<CustomerLinkMane> query(CustomerLinkManeQuery qo) {
        return customerLinkManeService.query(qo);
    }


    //新增
    @RequiresPermissions("business:customerLinkMane:add")
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CustomerLinkMane customerLinkMane) {
        customerLinkManeService.save(customerLinkMane);
        return AjaxResult.success();
    }

    //编辑
    @RequiresPermissions("business:customerLinkMane:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(CustomerLinkMane customerLinkMane) {
        customerLinkManeService.update(customerLinkMane);
        return AjaxResult.success();
    }

    //删除
    @RequiresPermissions("business:customerLinkMane:remove")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        customerLinkManeService.deleteBatch(ids);
        return AjaxResult.success();
    }


}
